package cloud.zhixinglu.www.spring.boot.fury.controller;

import cloud.zhixinglu.www.spring.boot.fury.pojo.bo.SendGptPredicateBO;
import cloud.zhixinglu.www.spring.boot.fury.pojo.bo.SendGptPredicatePayload;
import io.fury.Fury;
import io.fury.Language;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * FuryController
 * </p>
 *
 * @author weixin
 * @date 2023/8/25 14:07
 */
@RequestMapping("/fury/")
@RestController
public class FuryController {

    public static SendGptPredicateBO generateSend(){
        SendGptPredicateBO gptPredicate = new SendGptPredicateBO();
        SendGptPredicatePayload payload = new SendGptPredicatePayload();
        payload.setOperationId("a100");
        payload.setPhoneId("weiXin121");
        payload.setRequest("你是谁");

        List<Map<String, String>> history = new ArrayList<>(5);
        Map<String, String> history1 = new HashMap<>(1);
        Map<String, String> history2 = new HashMap<>(1);
        history1.put("你是谁", "我是ARKnovv，是致敬未知训练的语言模型。我可以帮助你回答问题，提供信息，甚至进行一些简单的对话。");
        history2.put("你是谁", "我是ARKnovv，是致敬未知训练的语言模型。我可以帮助你回答问题，提供信息，甚至进行一些简单的对话。");
        history.add(history1);
        history.add(history2);

        payload.setHistory(history);

        gptPredicate.setPayload(payload);
        return gptPredicate;
    }

    @GetMapping("test")
    public void fury(){
        Fury fury = Fury.builder().withLanguage(Language.XLANG)
                .withRefTracking(true).build();
        fury.register(SendGptPredicateBO.class, "example.SendGptPredicateBO");
        byte[] bytes = fury.serialize(generateSend());
        // bytes can be data serialized by other languages.
        System.out.println(fury.deserialize(bytes));
    }

}
